// 5. 日期&时间
/**
 * 1. 函数 #11
 *    time_t time(time_t *);
 *    char *ctime(const time_t *);
 *    struct tm *localtime(const time_t *);
 *    clock_t clock(void);
 *    char *asctime(const struct tm *);
 *    struct tm *gmtime(const time_t *);
 *    time_t mktime(struct tm *);
 *    double difftime(time_t e,time_t s);
 *    size_t strftime(char *str,int maxsize, char *format, const struct tm *tmptr);
 * 
 * 扩展:
 * 1. 
 * 
*/

#include <iostream>
#include <ctime>
#define __mark 11

/*
 * #11 函数使用
*/
#if __mark == 11

int main(void)
{
  time_t t;
  time(&t);

  std::cout << "now : " << ctime(&t) << std::endl;

  // clock_t s, e;

  // s = clock();
  // for (int i = 0; i < 10000; i++)
  // {
  // }
  // e = clock();

  // std::cout << "cpu 占时: " << (double)(e - s) / CLOCKS_PER_SEC << std::endl;

  struct tm info;
  struct tm *ptr;

  ptr = localtime(&t);

  std::cout << "本地时间:" << asctime(ptr) << std::endl;

  ptr = gmtime(&t);
  std::cout << "UTC时间:" << asctime(ptr) << std::endl;

  info.tm_year = 2021 - 1900;
  info.tm_mon = 9 - 1;
  info.tm_mday = 26;
  info.tm_hour = 12;
  info.tm_min = 30;
  info.tm_sec = 20;
  info.tm_isdst = -1;

  // t = mktime(&info);
  mktime(&info);

  std::cout << "time : " << asctime(&info) << std::endl;

  char str[30];
  strftime(str, 30, "%Y年%m月%d日 %H时%M分%S秒", &info);

  std::cout << "格式化时间字符串 : " << str << std::endl;

  printf("-------------end----------------\n");
  // system("pause");
  return 0;
}
#elif __mark == 'z'

int main()
{

  printf("-------------end----------------\n");
  // system("pause");
  return 0;
}

#endif